package exfist;
/**
 * Contains the details of the player at a given time. Ie position,image, is blocking etc.
 * @author brianmaccarthy
 */

import java.awt.Point;
import java.awt.image.BufferedImage;

public class Node
{
	// Instance variables: 
	protected  Node child;
	protected Point pos;
	protected String node_name;
	protected boolean doing_something,check_collision;
	protected boolean has_child;
	protected boolean player_high_block,player_low_block,is_hitable;
	protected BufferedImage sprite;
	public  Node() 
	{
	} 
	/**
	 * Creates a node with the given contents and next node.
	 * @param name the name of the node
	 * @param s the sprite of the current moment
	 * @param p the vector of movement (contained as a point because mathematically the same)
	 * @param hitable whether or not the player can be hit
	 */
    public  Node(String name,BufferedImage s,Point p,boolean hitable)  
    { 
    	node_name = name;
    	sprite = s;
    	pos = p;
    	has_child=false;
    	is_hitable = hitable;
    	check_collision=false;
    	player_high_block=false;
    	player_low_block=false;
    	doing_something = true;
    }
    // Accessor methods:
    /**
     * @return the sprite for the node
     */
    protected BufferedImage getSprite()
    {
    	return sprite;
    }
    /**
     * @return the x coordinate
     */
    protected int getPos_X()
    {
    	return pos.x;
    }
    /**
     * @return the y coordinate
     */
    protected int getPos_Y()
    {
    	return pos.y;
    }
    /**
     * @return the x & y position of that node
     */
    protected Point getPos()
    {
    	return pos;
    }
    /**
     * @return if has a child
     */
    protected boolean hasChild()
    {
    	return has_child;
    }
    /**
     * @return if blocking
     */
    protected boolean isHighBlocking()
    {
    	return player_high_block;
    }
    /**
     * currently useless,intended to block sweeps
     * @return if low blocking
     */
    protected boolean isLowBlocking()
    {
    	return player_low_block;
    }
    /**
     * @return the name of the node
     */
    protected String getNodeName()
    {
    	return node_name;
    }
    /**
     * @return if busy or not
     */
    protected boolean isBusy()
    {
    	return doing_something;
    }
    /**
     * @return the child of the node
     */
    protected Node getChild()  
    {
    	if(has_child!=false)
    		return  child;
    	else
    		System.out.println(this.node_name + " has no child");
    	return null;
    }
    // Modifier methods:
    /**
     * sets the sprite of the node
     * @param s the image
     */
    protected void setSprite(BufferedImage s)
    {
    	sprite=s;
    }
    /**
     * set the x coordinate
     * @param x the coord
     */
    protected void setPos_X(int x)
    {
    	pos.x=x;
    }
    /**
     * set the y coordinate
     * @param y the coord
     */
    protected void setPos_Y(int y)
    {
    	pos.y=y;
    }
    /**
     * set a new x&y position using a point
     * @param p the point
     */
    protected void setNewPos(Point new_pos)
    {
    	pos = new_pos;
    }
    /**
     * combines the x&y coords of the current and the given point
     * @param p the new point 
     */
    protected void updatePos(Point new_dir)
    {
    	pos.x+=new_dir.x;
    	pos.y+=new_dir.y;
    }
    /**
     * combines the x coords of the current and the given point
     * @param the new coord 
     */
    protected void updatePos_X(int x)
    {
    	pos.x+=x;
    }
    /**
     * combines the y coords of the current and the given point
     * @param the new coord 
     */
    protected void updatePos_Y(int y)
    {
    	pos.y+=y;
    }
    /**
     * add a child to the current node
     * @param newChild the child node
     */
    protected void setChild(Node newChild)  
    {
    	child  =  newChild; 
    	has_child = true;
    }
    /**
     * set blocking to true/false
     * @param b the boolean
     */
    protected void setHighBlocking(boolean b)
    {
    	player_high_block=b;
    }
    /**
     * set low blocking to true/false
     * @param b the boolean
     */
    protected void setLowBlocking(boolean b)
    {
    	player_low_block=b;
    }
    /**
     * set busy to true/false
     * @param b the boolean
     */
    protected void setBusy(boolean b)
    {
    	doing_something=b;
    }
    /**
     * remove a child
     * @param bad_parent the node to be removed
     */
    protected void removeChild(Node bad_parent)
    {
    	if(bad_parent.hasChild())
    	{
    		bad_parent.setChild(null);
        	bad_parent.has_child=false;
    	}
    }
}
